In this lecture, we'll see how we use the event
manager in our feed the teddies game. Here are our delegate declarations and
we're going to have to delegates for our events in this game,
we have a points added event and we have a game over event
in our event manager code. We have the typical structure for
in Voelker's and listeners for both those events. We don't actually need an invoker
interface like we did in the teddy bear destruction game because each of these
events is only invoked by one class. So the fries actor is the only class
that invokes the point at an event and the burger pond class is the only class
that invokes the game over event. So we don't have to build interfaces and
have these classes implement those interfaces,
we can just directly use the classes. Of course the code is longer
with multiple events so I can add the points at
an event in Voelker and remove it at the point at an event,
listener and remove it at the game of revenge
in Voelker and remove it and at the game over event listener and
remove it. So I need to provide
the capability to both add and remove in Voelker's and
listeners for every event I have. And in the implementation file I
implement all that functionality as usual as you saw when I did the event
manager for teddy bear destruction. That means that the French
fries actor needs to have a points added event included in it. And we need to be able to get access
to that point at an event and of course we'll have the French fries
remove themselves as an invoker of the event when they're
removed from the level. Which happens when they get destroyed or when they actually leave the level and
French fries add themselves as an invoker of this event here
in the begin play function. Just as we've seen before, the burger pond
is the invoker of the game over event, so again it's holding
a game over event here. It exposes a function so we can get
a reference to that game over event and it also removes itself as an invoker of the
event when it's removed from the level. That's right, and
it adds itself as an invoker of that event in its begin play function. So the way we use the event manager in
this game is the same as the way we used it when we talked about re factoring
the teddy bear destruction game, it's just that we have
two events this time. So the event manager code is a little
more complicated but we have simplified to some of the code because we don't
need to be implementing interfaces, we just have one class that invokes each
of those events to recap in this lecture. We explored how we use the event
manager in our feed, the kids game, we really have one more step to get our
event manager to be commercial quality. What we would probably do is define
an interface for each kind of event that gets invoked, for example
an event with one integer parameter. And then the event manager can just
use those interfaces instead of hard coded object or class names like
the fries actor or the burger upon. If we have multiple events that
have the same characteristics, for example, one integer parameter,
we also want to add an enema or an enumeration that had each
of the event names as values. And then when we registered or
added or removed in Voelker's or listeners to the event manager, we'd
also provide a parameter or an argument when we call the function that says which
event where adding to or removing from.